package com.tigerhhzz.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.tigerhhzz.springcloud.service.PaymentHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author tigerhhzz
 * @date 2023/4/15 10:03
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "Payment_Global_Fallback_Handler")
public class OrderHystrixController {

    @Resource
    private PaymentHystrixService paymentHystrixService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String getPaymentInfo_OK(@PathVariable("id") Integer id) {
        return paymentHystrixService.getPaymentInfo_OK(id);
    }

    @GetMapping("/consumer/payment/hystrix/error/{id}")
    //@HystrixCommand(fallbackMethod = "paymentInfo_ERROR_Handler",commandProperties = {
    //        @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
    //})
    @HystrixCommand
    public String paymentInfo_ERROR(@PathVariable("id") Integer id){
        int age= 10/0;
        return paymentHystrixService.getPaymentInfo_Error(id);
    }

    public String paymentInfo_ERROR_Handler(@PathVariable("id") Integer id){
        return "80____paymentInfo_ERROR_Handler___异常返回";
    }

    /*全局fallback方法  注意 这个全局兜底方法不能携带参数  这是我遇到的坑*/
    public String Payment_Global_Fallback_Handler(){
        return "80____Payment_Global_Fallback_Handler___异常返回";
    }

}
